58 lines · 1.7 KB
1 ---
2 import Repo from '../../../layouts/Repo.astro';
3 import { apiGet } from '../../../lib/api';
4
5 const { owner, repo } = Astro.params;
6 const cookie = Astro.request.headers.get('cookie') || '';
7
8 let branches: any[] = [];
9 let defaultBranch = 'main';
10 let error = '';
11
12 try {
13 const data = await apiGet(`/api/repos/${owner}/${repo}/branches`, cookie);
14 branches = data.branches || [];
15 defaultBranch = data.default_branch || 'main';
16 } catch (e: any) {
17 error = e.message;
18 }
19 ---
20
21 <Repo owner={owner!} repo={repo!} activeTab="branches">
22 {error && <div class="flash-error">{error}</div>}
23
24 <h2 style="font-size: 1rem; margin-bottom: 16px;">Branches</h2>
25
26 <div class="card" style="padding: 0; overflow: hidden;">
27 {branches.map((branch: any) => (
28 <div style="
29 display: flex;
30 justify-content: space-between;
31 align-items: center;
32 padding: 12px 16px;
33 border-bottom: 1px solid var(--border);
34 font-size: 0.875rem;
35 ">
36 <div style="display: flex; align-items: center; gap: 8px;">
37 <a href={`/${owner}/${repo}/tree/${branch.name}`} style="font-weight: 500;">
38 {branch.name}
39 </a>
40 {branch.isDefault && (
41 <span style="font-size: 0.75rem; border: 1px solid var(--accent); color: var(--accent); border-radius: 12px; padding: 0 8px;">
42 default
43 </span>
44 )}
45 </div>
46 <code style="color: var(--text-muted); font-size: 0.75rem;">
47 {branch.sha.slice(0, 7)}
48 </code>
49 </div>
50 ))}
51 {branches.length === 0 && (
52 <div style="padding: 32px; text-align: center; color: var(--text-muted);">
53 No branches yet. Push some code to create the first branch.
54 </div>
55 )}
56 </div>
57 </Repo>
58